package ltd.dujiabao.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ltd.dujiabao.eduservice.entity.EduTeacher;
import ltd.dujiabao.eduservice.entity.vo.TeacherQuery;
import ltd.dujiabao.eduservice.mapper.EduTeacherMapper;
import ltd.dujiabao.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author dujiabao
 * @since 2021-04-18
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

  @Override
  public IPage<EduTeacher> pageQuery(Page<EduTeacher> page, TeacherQuery teacherQuery) {
    if (teacherQuery == null) {
      this.page(page, null);
      return page;
    }

    QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
    if (!StringUtils.isEmpty(teacherQuery.getName())) {
      wrapper.like("name", teacherQuery.getName());
    }

    if (teacherQuery.getLevel() != null) {
      wrapper.eq("level", teacherQuery.getLevel());
    }

    if (!StringUtils.isEmpty(teacherQuery.getBegin())) {
      wrapper.ge("gmt_create", teacherQuery.getBegin());
    }
    if (!StringUtils.isEmpty(teacherQuery.getEnd())) {
      wrapper.le("gmt_create", teacherQuery.getEnd());
    }
    wrapper.orderByDesc("gmt_create");
    this.page(page, wrapper);
    return page;
  }
}
